package org.fig.dependency.lookup;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.annotation.PostConstruct;

/**
 * @Description:
 * @Author: Flynn Vanderboom
 * @Data: 2021/6/18 15:00
 */

public class BeanCreationExceptionDemo {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();

        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(POJO.class);
        applicationContext.registerBeanDefinition("errBean",builder.getBeanDefinition());

        applicationContext.refresh();

        applicationContext.close();

    }

    static class POJO implements InitializingBean{

        @PostConstruct //CommonAnnotationBeanPostProcessor 来处理该注解
        public void init() throws Throwable{
            throw new Exception("init() ： For purpose。。。");
        }

        @Override
        public void afterPropertiesSet() throws Exception {
            throw new Exception("afterPropertiesSet() ： For purpose。。。");
        }
    }
}
